﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;

namespace MainWindow
{
	/// <summary>
	/// Interaction logic for ConfigDialog.xaml
	/// </summary>
	public partial class ConfigDialog : Window
	{
		public string Username
		{
			get { return usrTextBox.Text; }
			set { usrTextBox.Text = value; }

		}
		public string Password
		{
			get { return pwdTextBox.Password; }
			set { pwdTextBox.Password = value; }
		}
		public string SavePath
		{
			get { return pathTextBox.Text; }
			set { pathTextBox.Text = value; }
		}
		public string PrintPath
		{
			get { return printTextBox.Text; }
			set { printTextBox.Text = value; }
		}
		public int SizeLimit
		{
			get
			{
				try
				{
					bool? a = limitCheckBox.IsChecked;
					if (a.HasValue && a.Value)

						return Convert.ToInt32(sizeLimitTextBox.Text);
					else
						return -1;
				}
				catch
				{
					return -1;
				}
			}
			set
			{
				if (value == -1)
					limitCheckBox.IsChecked = false;
				else
				{
					limitCheckBox.IsChecked = true;
					sizeLimitTextBox.Text = value.ToString();
				}
			}
		}
		public bool Remember
		{
			get
			{
				bool? a = recCheckBox.IsChecked;
				if (a.HasValue && a.Value)
					return true;
				else
					return false;
			}
		}



		public ConfigDialog()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, RoutedEventArgs e)
		{
			FolderBrowserDialog sfd = new FolderBrowserDialog();
			//Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
			sfd.Description = "Choose Download Folder";
			if (sfd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
				pathTextBox.Text = sfd.SelectedPath;
		}

		private void button2_Click(object sender, RoutedEventArgs e)
		{
			bool? b = limitCheckBox.IsChecked;
			if (b.HasValue && b.Value)
			{
				try
				{
					int a = Convert.ToInt32(sizeLimitTextBox.Text);
					if (a > 0)
						this.DialogResult = true;
					else
					{
						System.Windows.Forms.MessageBox.Show("Please input a valid size limit integer.");
						return;
					}
				}
				catch
				{
					System.Windows.Forms.MessageBox.Show("Please input a valid size limit integer.");
					return;
				}
				
			}
			else
				this.DialogResult = true;					
			
		}

		private void button3_Click(object sender, RoutedEventArgs e)
		{
			this.DialogResult = false;
		}

		private void printPathButton_Click(object sender, RoutedEventArgs e)
		{
			FolderBrowserDialog sfd = new FolderBrowserDialog();
			//Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
			sfd.Description = "Choose Print Folder";
			if (sfd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
				printTextBox.Text = sfd.SelectedPath;
		}

		private void limitCheckBox_Checked(object sender, RoutedEventArgs e)
		{
			sizeLimitTextBox.IsEnabled = true;
			unitLabel.IsEnabled = true;
		}

		private void limitCheckBox_Unchecked(object sender, RoutedEventArgs e)
		{
			sizeLimitTextBox.IsEnabled = false;
			unitLabel.IsEnabled = false;
		}
	}
}
